﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.IO;
using WebVideo.Areas.Admin.Models;
using System.Collections;


namespace WebVideo.Areas.Admin.Models
{
    public class ListQuestionOfUserModel
    {
        public int Id { get; set; }
        public string UserName { get; set; }
        public string IdQuestion { get; set; }
        public string Result { get; set; }

        public static IEnumerable<ListModel> LayDuLieu()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            var query = from p in db.EntityListQuestionOfUsers
                        orderby p.Date descending
                        group p by new { p.UserName, p.EntityQuestions_Essay.EntityVideo.Id, p.EntityQuestions_Essay.EntityVideo.Name } into Group
                        select new { Group.Key.UserName, Group.Key.Id,Group.Key.Name  };

            List<ListModel> x = new List<ListModel>();
            foreach (var d in query)
            {
                ListModel a = new ListModel();
                a.UserName = d.UserName;
                a.IdVieo    = d.Id  ;
                a.Name = d.Name;
                x.Add(a);
            }
            return x;
        }
        // 
        public static IEnumerable<EntityListQuestionOfUser> LayDS(string UserName, int IdVideo)
        {
            dbVideoDataContext db = new dbVideoDataContext();
            var query = (from p in db.EntityListQuestionOfUsers
                        where p.UserName == UserName && p.EntityQuestions_Essay.EntityVideo.Id == IdVideo 
                        select p).Distinct();
            return query.ToList();
        }

    }
}